//package com.aaa.tmr.util;
//
//import com.aaa.tmr.entity.OperLog;
//import com.aaa.tmr.entity.User;
//import com.aaa.tmr.service.OperLogService;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import java.util.Date;
//
///**
// * @ fileName:OperLogUtil
// * @ description: 使用AOP技术统计记录操作日志（只包含增删改）
// * @ author:zhz
// * @ createTime:2021/3/22 14:19
// */
//@Component
//@Aspect   //标记为切面实现类
//public class OperLogUtil {
//
//    @Resource
//    private OperLogService operLogService;
//
//
//    @Resource
//    private HttpSession session;
//
//    /**
//     * 操作日志记录功能
//     * @param joinPoint
//     */
//    @AfterReturning(pointcut = "execution(* com.aaa.tmr.service.impl.*.insert*(..)) " +
//            "|| execution(* com.aaa.tmr.service.impl.*.update*(..))" +
//            "|| execution(* com.aaa.tmr.service.impl.*.batch*(..))" +
//            "|| execution(* com.aaa.tmr.service.impl.*.delete*(..))")
//    public void  recordOperLog(JoinPoint joinPoint){
//        OperLog operLog =new OperLog();
//        operLog.setTitle("商标注册");
//        //获取执行方法的名称
//        String methodName = joinPoint.getSignature().getName();
//        int bussinessType= BussinessConstants.OperBussinessType.DELETE;
//        if(methodName.contains("insert")){
//            bussinessType= BussinessConstants.OperBussinessType.ADD;
//        }else  if(methodName.contains("update")){
//            bussinessType= BussinessConstants.OperBussinessType.UPDATE;
//        }
//        operLog.setBusinessType(bussinessType);
//        //带包的类名称 获取类的限定名
//        String className = joinPoint.getTarget().getClass().getName();
//        operLog.setMethod(className+"."+methodName);
//        operLog.setOperatorType(1);
//        //获取当前登录人信息
//        User user = (User)session.getAttribute("userInfo");
//        if(user!=null){
//            operLog.setOperName(user.getUserName());
//        }
//        operLog.setDeptName("开发部门");
//        //获取HttpServletRequest
//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = requestAttributes.getRequest();
//        //获取uri
//        String requestURI = request.getRequestURI();
//        operLog.setOperUrl(requestURI);
//        //获取请求的IP地址
//        String remoteAddr = request.getRemoteAddr();
//        operLog.setOperIp(remoteAddr);
//        operLog.setOperLocation("zz");
//        operLog.setStatus(0);
//        //获取操作参数
//        //String queryString = request.getQueryString();
//        Object[] args = joinPoint.getArgs();
//        if(args!=null&&args.length>0){
//            operLog.setOperParam(args[0].getClass().getSimpleName());
//        }
//        operLog.setOperTime(new Date());
//        operLogService.insert(operLog);
//    }
//
//  /*  @AfterThrowing(pointcut = "execution(* com.aaa.tmr.service.impl.*.insert*(..)) " +
//            "|| execution(* com.aaa.tmr.service.impl.*.update*(..))" +
//            "|| execution(* com.aaa.tmr.service.impl.*.delete*(..))",throwing = "e")
//    public void recordExceptionLog(JoinPoint joinPoint,Exception e){
//        OperLog operLog =new OperLog();
//        operLog.setTitle("商标注册");
//        //获取执行方法的名称
//        String methodName = joinPoint.getSignature().getName();
//        int bussinessType=BussinessConstants.OperBussinessType.DELETE;
//        if(methodName.contains("insert")){
//            bussinessType=BussinessConstants.OperBussinessType.ADD;
//        }else  if(methodName.contains("update")){
//            bussinessType=BussinessConstants.OperBussinessType.DELETE;
//        }
//        operLog.setBusinessType(bussinessType);
//        //带包的类名称 获取类的限定名
//        String className = joinPoint.getTarget().getClass().getName();
//        operLog.setMethod(className+"."+methodName);
//        operLog.setOperatorType(1);
//        //获取当前登录人信息
//        User user = (User)session.getAttribute("userInfo");
//        operLog.setOperName(user.getUserName());
//        operLog.setDeptName("开发部门");
//        //获取HttpServletRequest
//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = requestAttributes.getRequest();
//        //获取uri
//        String requestURI = request.getRequestURI();
//        operLog.setOperUrl(requestURI);
//        //获取请求的IP地址
//        String remoteAddr = request.getRemoteAddr();
//        operLog.setOperIp(remoteAddr);
//        operLog.setOperLocation("zz");
//        operLog.setStatus(1);
//        operLogService.insert(operLog);
//    }*/
//}
